<?php
	$cur_page_ver="0.1d";
	$this_page="user\offlines";
	if(isset($_POST['action']) && $_POST['action']=='Reply')
	{
		header("Location: reply.php?msg=".$_POST['MSGID']);
		echo "Redirecting!";
		exit;
	}	
	require_once('../includes/global.php');
	!isset($_SESSION['logged_as_user'])?die("You must be logged in to view this page"):null;
	if(isset($_POST['action']))
	{
		//echo "in if\n";
		switch($_POST['action'])
		{
		case "Delete":
			//echo "Delete\n";
			$dbcon->executeSQL("DELETE FROM `offlines` WHERE `offline_id`=".$_POST['MSGID']." AND `to`=".$_SESSION['uid']);
			break;
		case "Delete All":
			//echo "Delete All\n";
			$dbcon->executeSQL("DELETE FROM `offlines` WHERE `to`=".$_SESSION['uid']);
			break;
		case "Reply":
			//echo "Reply\n";
			break;
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html; iso-8859-1" />
		<meta name="title" content="Codename: STIMPy!" />
		<meta name="author" content="Codename: STIMPy! Dev Team" />
		<meta name="publisher" content="Codename: STIMPy! Dev Team" />
		<meta name="copyright" content="www.codenamestimpy.com" />
		<meta http-equiv="Reply-to" content="stimpy@codenamestimpy.com" />
		<meta name="creation_Date" content="04/02/2006" />
		<meta name="expires" content="" />
		<TITLE>STIMPy! &gt; User &gt; Offlines</TITLE>
		<link href="../stimpy_main.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript">
			<!-- //Hiding from older browsers
			var aMessage=new Array('<?php $result=$dbcon->query("SELECT `text` FROM offlines
			WHERE `to`=".$_SESSION['uid']);
			if(count($result)==1)
			{
				echo $result['text']."'";
				$firstMSG=$result['text'];
			}
			else
			{
				$trigger=true;
				foreach($result as $row)
				{
					if(!$trigger)
					{
						echo ", '";
					}
					else
					{
						$trigger=false;
						$firstMSG=$row['text'];
					}
					echo $row['text']."'";
				}
			}
			echo ");\n";?>
			var iNumOfflines=<?php echo $dbcon->numRows($result); $close=(!$result?true:false);?>;
			var aMessageID=new Array(<?php 
			$result=$dbcon->query("SELECT `offline_id` FROM offlines
			WHERE `to`=".$_SESSION['uid']);
			if(count($result)==1)
			{
				echo $result['offline_id'];
				$firstID=$result['offline_id'];
			}
			else
			{
				$trigger=true;
				foreach($result as $row)
				{
					if(!$trigger)
					{
						echo ', ';
					}
					else
					{
						$trigger=false;
						$firstID=$row['offline_id'];
					}
					echo $row['offline_id'];
				}
			}
			echo ");\n";?>
			// done hiding -->
		</script>
	</HEAD>
	<BODY<?php if($close){?> onload="Javascript: window.close()"<?php }?>>
		<form id="frmOfflines" name="frmOfflines" method="post" action="">
			<table border="0" align="center">
				<tr>
					<td align="center">
						<select name="lstHeader" size="5" id="lstHeader" onchange="Javascript: document.frmOfflines.msgBody.value=''; document.frmOfflines.msgBody.value=aMessage[document.frmOfflines.lstHeader.selectedIndex]; document.frmOfflines.MSGID.value=aMessageID[document.frmOfflines.lstHeader.selectedIndex];">
<?php
							$result=$dbcon->query("SELECT `UN` , `time`
													FROM `offlines` AS o
													LEFT JOIN `users` AS u ON o.`from` = u.UID
													WHERE o.`to` =".$_SESSION['uid']);
							if(!isset($result[0]['UN']))
							{
								echo "<option selected>From: ".$result['UN']."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time: ".$result['time']."</option>";
							}
							else
							{
								$trigger=true;
								foreach($result as $row)
								{?>
								<option value="<?php echo (isset($j)?$j:0).'"'; $j++; if($trigger){ echo " selected"; $trigger=false;} ?>>From: <?php echo $row['UN']; for($x=strlen($row['UN']);$x<=20;$x++) { echo "&nbsp;"; } ?>Time: <?php echo $row['time']; ?></option><?echo "\n\r"; }} ?>
						</select>
					</td>
				</tr>
				<tr>
					<td align="center"><textarea name="msgBody" id="msgBody" cols="40" rows="5"><?php echo $firstMSG; ?></textarea></td>
				</tr>
				<tr>
					<td align="right">
						<input type="hidden" value="<?php echo $firstID; ?>" name="MSGID" />
						<input type="submit" name="action" value="Delete" />
						<input type="submit" name="action" value="Delete All" />
						<input type="submit" name="action" value="Reply" onclick="document.location='reply.php?msg='+document.frmOfflines.MSGID.value;" />
					</td>
				</tr>
			</table>
		</form>
	</BODY>
</HTML>